<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>分析生命周期</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="root">
    <h2>{{n}}</h2>
    <button @click="add">n+1</button>
    <button @click="bye">销毁</button>
  </div>

  <script>
    Vue.config.productionTip = false

    new Vue({
      el: '#root',
      data: {
        n: 0
      },
      methods: {
        add() {
          this.n++
        },
        bye() {
          this.$destroy()
        }
      },
      beforeCreate() {
        console.log('beforeCreate')
      },
      created() {
        console.log('created')
      },
      beforeMount() {
        console.log('beforeMount')
      },
      mounted() {
        console.log('mounted')
      },
      beforeUpdate() {
        console.log('beforeUpdate')
      },
      updated() {
        console.log('updated')
      },
      beforeDestroy() {
        console.log('beforeDestroy')
      },
      destroyed() {
        console.log('destroyed')
      },
    })
  </script>
</body>

</html>